package com.zzptc.easyshop.dao;

import com.zzptc.easyshop.db.IDB;
import com.zzptc.easyshop.db.MysqlDB;
import com.zzptc.easyshop.vo.Product;
import com.zzptc.easyshop.vo.Users;
import com.zzptc.easyshop.vo.VO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProductDao implements IDAO {
    @Override
    public boolean insert(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean updete(VO vo) throws SQLException {
        List<Product> list=new ArrayList<>();
        IDB db=new MysqlDB();
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs = null;
        try {
            conn=db.getConn();
            String sql=" update easybuy_product  set ep_name='米奇和米妮'      where name ='米老鼠'";
            ps=conn.prepareStatement(sql);
            rs=ps.executeQuery();
            //循环遍历虚拟表 放入集合对象
            while(rs.next()){
                Product pro=new Product();
                pro.setEp_id(rs.getInt("Ep_id"));
                pro.setEp_name(rs.getString("Ep_name"));
                pro.setEp_description(rs.getString("Ep_description"));
                pro.setEp_price(rs.getFloat("Ep_price"));
                pro.setEp_stock(rs.getInt("Ep_stock"));
                pro.setEpc_id(rs.getInt("Epc_id"));;
                pro.setEpc_child_id(rs.getInt("Epc_child_id"));
                pro.setEp_file_name(rs.getString("Ep_file_name"));
                boolean add;
                add = list.add(pro);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            //关闭数据库连接   释放资源

            try {
                db.closeAll(conn,ps,rs);

            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
    @Override
    public boolean delete(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean login(VO vo) throws SQLException {
        return false;
    }

    @Override
    public List<Users> getAll() throws SQLException {
        return null;
    }
}
